﻿using System;
using System.IO;

namespace OpenLS.Spreadsheet.Formats.Biff.OfficeArt
{
    internal abstract class OfficeArtSolverContainerFileBlock // Parent for 0xF012 OfficeArtFConnectorRule
//0xF014
//OfficeArtFArcRule
//0xF017
//OfficeArtFCalloutRule
    {
        private readonly OfficeArtRecordHeader _header;

        public OfficeArtSolverContainerFileBlock(OfficeArtRecordHeader header)
        {
            _header = header;
        }

        internal static OfficeArtSolverContainerFileBlock Read (BinaryReader reader)
        {
            OfficeArtRecordHeader header = new OfficeArtRecordHeader();
            OfficeArtSolverContainerFileBlock result;
            header.Read(reader);
            switch (header.recType)
            {
                case RecType.OfficeArtFConnectorRule:
                    result = new OfficeArtFConnectorRule(header);
                    break;
                case RecType.OfficeArtFArcRule:
                    result = new OfficeArtFArcRule(header);
                    break;
                case RecType.OfficeArtFCalloutRule:
                    result = new OfficeArtFCalloutRule(header);
                    break;
                    break;
                default:
                    throw new NotSupportedException();
            }
            result.ReadNoHeader(reader);
            return result;
        }

        protected abstract void ReadNoHeader(BinaryReader reader);


        public void Write(BinaryWriter writer)
        {
            throw new NotImplementedException();
        }


        public int ByteLength
        {
            get { throw new NotImplementedException(); }
        }

        public static decimal Size
        {
            get { throw new NotImplementedException(); }
        }
    }

    internal class OfficeArtFCalloutRule : OfficeArtSolverContainerFileBlock
    {
        private uint ruid;
        private uint spid;

        public OfficeArtFCalloutRule(OfficeArtRecordHeader header) : base(header)
        {
        }

        protected override void ReadNoHeader(BinaryReader reader)
        {
            this.ruid = reader.ReadUInt32();
            this.spid = reader.ReadUInt32();
        }
    }

    internal class OfficeArtFArcRule : OfficeArtSolverContainerFileBlock
    {
        private uint ruid;
        private uint spid;

        public OfficeArtFArcRule(OfficeArtRecordHeader header) : base(header)
        {
        }

        protected override void ReadNoHeader(BinaryReader reader)
        {
            this.ruid = reader.ReadUInt32();
            this.spid = reader.ReadUInt32();
        }
    }

    internal class OfficeArtFConnectorRule : OfficeArtSolverContainerFileBlock
    {
        private uint ruid;
        private uint spidA;
        private uint spidB;
        private uint spidC;
        private uint cptiA;
        private uint cptiB;

        public OfficeArtFConnectorRule(OfficeArtRecordHeader header) : base(header)
        {
        }

        protected override void ReadNoHeader(BinaryReader reader)
        {
            this.ruid = reader.ReadUInt32();
            this.spidA = reader.ReadUInt32();
            this.spidB = reader.ReadUInt32();
            this.spidC = reader.ReadUInt32();
            this.cptiA = reader.ReadUInt32();
            this.cptiB = reader.ReadUInt32();
        }
    }
}